library(tidyverse)
library(sf)
library(readr)
library(mapview)
Rxdeploy <- read_csv("../data/deployments.csv") #receiver station info

head(Rxdeploy)
## # A tibble: 6 x 23
##   station glatos_array station_no consecutive_dep… intend_lat intend_long
##   <chr>   <chr>             <dbl>            <dbl> <lgl>      <lgl>      
## 1 WHT-009 WHT                   9                1 NA         NA         
## 2 FDT-001 FDT                   1                2 NA         NA         
## 3 FDT-004 FDT                   4                2 NA         NA         
## 4 FDT-003 FDT                   3                2 NA         NA         
## 5 FDT-002 FDT                   2                2 NA         NA         
## 6 DTR-001 DTR                   1                2 NA         NA         
## # … with 17 more variables: deploy_lat <dbl>, deploy_long <dbl>,
## #   recover_lat <lgl>, recover_long <lgl>, deploy_date_time <dttm>,
## #   recover_date_time <dttm>, bottom_depth <dbl>, riser_length <dbl>,
## #   instrument_depth <dbl>, ins_model_no <chr>,
## #   glatos_ins_frequency <dbl>, ins_serial_no <dbl>, deployed_by <lgl>,
## #   comments <lgl>, glatos_seasonal <chr>, glatos_project <chr>,
## #   glatos_vps <chr>
rec_sf <-
  Rxdeploy %>% 
  st_as_sf(coords = c("deploy_long", "deploy_lat")) ## specify which columns contain the longitude and latitude data

head(rec_sf)
## Simple feature collection with 6 features and 21 fields
## geometry type:  POINT
## dimension:      XY
## bbox:           xmin: -83.8974 ymin: 43.74216 xmax: -82.50791 ymax: 45.97745
## epsg (SRID):    NA
## proj4string:    NA
## # A tibble: 6 x 22
##   station glatos_array station_no consecutive_dep… intend_lat intend_long
##   <chr>   <chr>             <dbl>            <dbl> <lgl>      <lgl>      
## 1 WHT-009 WHT                   9                1 NA         NA         
## 2 FDT-001 FDT                   1                2 NA         NA         
## 3 FDT-004 FDT                   4                2 NA         NA         
## 4 FDT-003 FDT                   3                2 NA         NA         
## 5 FDT-002 FDT                   2                2 NA         NA         
## 6 DTR-001 DTR                   1                2 NA         NA         
## # … with 16 more variables: recover_lat <lgl>, recover_long <lgl>,
## #   deploy_date_time <dttm>, recover_date_time <dttm>, bottom_depth <dbl>,
## #   riser_length <dbl>, instrument_depth <dbl>, ins_model_no <chr>,
## #   glatos_ins_frequency <dbl>, ins_serial_no <dbl>, deployed_by <lgl>,
## #   comments <lgl>, glatos_seasonal <chr>, glatos_project <chr>,
## #   glatos_vps <chr>, geometry <POINT>
plot(rec_sf["glatos_array"])

rec_sf <-
  Rxdeploy %>% 
  st_as_sf(coords = c("deploy_long", "deploy_lat"),
           crs = 4326)    ## specify your epsg code in the crs parameter 

rec_sf
## Simple feature collection with 898 features and 21 fields
## geometry type:  POINT
## dimension:      XY
## bbox:           xmin: -84.762 ymin: 41.56911 xmax: -79.32217 ymax: 46.54273
## epsg (SRID):    4326
## proj4string:    +proj=longlat +datum=WGS84 +no_defs
## # A tibble: 898 x 22
##    station glatos_array station_no consecutive_dep… intend_lat intend_long
##    <chr>   <chr>             <dbl>            <dbl> <lgl>      <lgl>      
##  1 WHT-009 WHT                   9                1 NA         NA         
##  2 FDT-001 FDT                   1                2 NA         NA         
##  3 FDT-004 FDT                   4                2 NA         NA         
##  4 FDT-003 FDT                   3                2 NA         NA         
##  5 FDT-002 FDT                   2                2 NA         NA         
##  6 DTR-001 DTR                   1                2 NA         NA         
##  7 DTR-002 DTR                   2                2 NA         NA         
##  8 DTR-003 DTR                   3                2 NA         NA         
##  9 DTR-004 DTR                   4                2 NA         NA         
## 10 LVD-001 LVD                   1                1 NA         NA         
## # … with 888 more rows, and 16 more variables: recover_lat <lgl>,
## #   recover_long <lgl>, deploy_date_time <dttm>, recover_date_time <dttm>,
## #   bottom_depth <dbl>, riser_length <dbl>, instrument_depth <dbl>,
## #   ins_model_no <chr>, glatos_ins_frequency <dbl>, ins_serial_no <dbl>,
## #   deployed_by <lgl>, comments <lgl>, glatos_seasonal <chr>,
## #   glatos_project <chr>, glatos_vps <chr>, geometry <POINT [°]>
plot(rec_sf["glatos_array"])

mapview(rec_sf)
mapview(rec_sf, 
        zcol = "glatos_project",
        burst = TRUE)